package com.wq.sms.listener;

import com.aliyuncs.exceptions.ClientException;
import com.wq.sms.uitl.SmsUtil;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@RabbitListener(queues = "sms")
@Component
public class SmsListener {
    @Autowired
    private SmsUtil smsUtil;
    //模板编号
    @Value("${aliyun.sms.template_code}")
    private String template_code;
    //签名
    @Value("${aliyun.sms.sign_name}")
    private String sign_name;
    //发送短信
    @RabbitHandler
    public void getMsg(Map<String,String> map){
        System.out.println("手机号："+map.get("phone"));
        System.out.println("验证码"+map.get("code"));
        try {
            smsUtil.sendSms(map.get("phone"), template_code, sign_name, "{\"code\":\""
                    + map.get("code") + "\"}");
        } catch (ClientException e) {
            e.printStackTrace();
        }

    }
}
